package com.zrf.base.knowledge.sort;

/**
 * 冒泡排序
 * @author zhouruifeng
 *         create at 2017/3/5.
 */
public final class BubbleSort {

    private BubbleSort(){

    }

    /**
     * 对数据进行冒泡排序
     * @param a 数组a
     */
    public static void sort(int[] a){
        int length = a.length;

        for (int i = 0; i < length; i++) {
            for (int j = 0; j< length-i-1; j++){
                if (a[j] > a[j+1]){
                    int tmp = a[j];
                    a[j] = a[j+1];
                    a[j+1] = tmp;
                }
            }
        }
    }

    /**
     * main方法
     * @param args 参数
     */
    public static void main(String[] args){
        int[] a = new int[]{3, 2, 1, 5, 7, 8, 1, 1, 12, 3, 4, 5, 6};

        sort(a);

        for (int i = 0; i < a.length; i++) {
            System.out.print(a[i] + ",");
        }
    }
}
